package com.xkdx.guangguang.bhg;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.xkdx.caipiao.R;
import com.xkdx.guangguang.UserActivity;
import com.xkdx.guangguang.fragment.user.UserSharePrefence;
import com.xkdx.guangguang.module.statics.IConstants;

public class BhgActivity extends Activity {
	ImageView exchange_intro, get;
	RelativeLayout intro;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.bhg_activity);
		init();
		setOnClick();
	}

	private void init() {
		exchange_intro = (ImageView) findViewById(R.id.btn_exchange);
		get = (ImageView) findViewById(R.id.btn_get);
		intro = (RelativeLayout) findViewById(R.id.bhg_intro);

	}

	private void setOnClick() {
		exchange_intro.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				intro.setVisibility(View.VISIBLE);

			}
		});
		get.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				UserSharePrefence sp_user = new UserSharePrefence(
						BhgActivity.this, IConstants.SP_USER);
				String loginToken = sp_user.getUserLoginToken();
				if ("".equals(loginToken)) {
					UserLogin();
				} else {
					IConstants.BottomBtnSelected = 5;
					Intent intent = new Intent(BhgActivity.this,
							UserActivity.class);
					intent.putExtra("fragment", "ExchangeListFragment");
					startActivity(intent);
				}
			}
		});
		intro.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				intro.setVisibility(View.GONE);
			}
		});

	}

	public void UserLogin() {

		AlertDialog.Builder ab = new AlertDialog.Builder(this);
		ab.setTitle("提示");
		ab.setMessage("请先登录");
		ab.setPositiveButton("确定", new DialogInterface.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				IConstants.BottomBtnSelected = 5;
				Intent intent = new Intent(BhgActivity.this, UserActivity.class);
				intent.putExtra("fragment", "UserLoginFragment");
				startActivity(intent);
			}
		});
		ab.setNegativeButton("取消", null);
		ab.create().show();

	}

}
